package homework711;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

public class work1server extends Thread {
	private Socket s;

	public work1server(Socket s) {
		this.s = s;
	}

	private Map<String, Object> map = new HashMap<>();
	{
		map.put("张三", "aa123");
		map.put("李四", "bb123");
	}

	@Override
	public void run() {
		try {
			System.out.println("连接成功");
			OutputStream out = s.getOutputStream();
			InputStream in = s.getInputStream();
			ObjectOutputStream oin = new ObjectOutputStream(out);
			ObjectInputStream oo = new ObjectInputStream(in);
			String a = (String) oo.readObject();
			String b = (String) oo.readObject();
			System.out.println("收到了");
			if (map.containsKey(a)) {
				if (map.get(a).equals(b)) {
					oin.writeObject("登陆成功！");
				} else {
					oin.writeObject("密码错误！");
				}
			} else {
				oin.writeObject("无此账号！");
			}
			oin.close();
			PrintWriter pw = new PrintWriter(out);
			Object obj = new Object();
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} finally {
			try {

				s.close();
			} catch (Exception e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
		}

	}
}
